<!DOCTYPE html>
<html>
<head>
	<title>接口自动生成</title>
	<meta charset="utf-8">
  <script src="jquery-3.2.1.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.11/vue.min.js"></script>
<link href="https://cdn.bootcss.com/element-ui/2.13.2/theme-chalk/index.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/element-ui/2.13.2/index.js"></script> 

</head>
<body>
<div id="app" v-loading.fullscreen.lock="fullscreenLoading">
	<textarea id="textArea" placeholder="本接口自动生成利用正则表达式，目前支持提交控制器文本，服务器仓库路径,远程仓库3种，只要符合示例规范的resultful控制器均可使用该方式生成文档" style="height:-webkit-fill-available;width:-webkit-fill-available" v-model="text"></textarea>
	<div style="position:fixed;right:20%;top:50%;width:100px;height:100px">
	<input type="button" value="提交" @click="commitText" style="width:50px;height:50px;border-radius:50%">
	<input type="button" value="文本" @click="commit('text')" style="width:50px;height:50px;border-radius:50%">
  <input type="button" value="路径" @click="commit('path')" style="width:50px;height:50px;border-radius:50%">
  <input type="button" value="仓库" @click="commit('git')" style="width:50px;height:50px;border-radius:50%">
	<input type="button" value="帮助" @click="help" style="width:50px;height:50px;border-radius:50%">
    <input type="button" value="历史" @click="history" style="width:50px;height:50px;border-radius:50%">
    </div>
   <!-- 
    <input id="files" type = "file" webkitdirectory>
      console.log(document.getElementById("files").files);
    -->

    <div id="popWindow" @click="closeDiv" class="popWindow" style="display: none;"> 
</div> 


<div id="maskLayer1" class="maskLayer" style="display: none;">
    <h2>测试单</h2><textarea style="top: 20px;position: sticky;margin-right: 10px;" v-model="rootUrl" placeholder="请输入地址前缀，例如http://localhost">
    </textarea><textarea style="top: 20px;position: sticky;margin-right: 10px;" v-model="header" placeholder='请输入Json格式的公用请求头信息，例如{"Cookie":"123","token":"abc"}'>
    </textarea><el-button @click="test(1)" style="background-color: #f3f3f3">开始执行测试</el-button><el-button @click="download(1)" style="background-color: #f3f3f3">下载文档</el-button><el-button  @click="showDiv(2)" style="background-color: #f3f3f3">返回</el-button>

 <template >
  <el-table
    :data="model.method"
    style="width: 100%">
    <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
          <el-table
    :data="props.row.methodParam"
    style="width: 100%">
      <el-table-column
      label="参数名称"
      prop="paramName">
    </el-table-column>
    <el-table-column
      label="参数类型"
      prop="paramType">
    </el-table-column>
    <el-table-column
      label="是否必选"
      >
       <template slot-scope="scope">
        {{scope.row.paramNeed}}
      </template>
    </el-table-column>
    <el-table-column
      label="备注"
      prop="paramRemark">
    </el-table-column>
    <el-table-column
      label="赋值"
      prop="propsparamValue">
      <template slot-scope="props">
      <el-input type="text" v-model="props.row.paramValue"></el-input>
      </template>
    </el-table-column>
    </el-table>
        </el-form>
      </template>
    </el-table-column>
     <el-table-column
      label="接口类型"
      prop="methodType">
    </el-table-column>
    <el-table-column
      label="接口地址"
      prop="methodUrl">
    </el-table-column>
    <el-table-column
      label="接口描述"
      prop="methodRemark" show-overflow-tooltip = "true">
    </el-table-column>
     <el-table-column
      label="返回类型"
      prop="methodReturn">
    </el-table-column>
    <el-table-column
      label="状态"
      prop="methodRunstatus">
    </el-table-column>
    <el-table-column
      label="执行时间"
      prop="methodRuntime">
    </el-table-column>
    <el-table-column
      label="执行结果"
      prop="methodRunresult" show-overflow-tooltip = "true">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" name="查看" size="small">编辑</el-button>
        <el-button type="text" @click="test(0,scope.row)" name="执行" size="small">执行</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

 </div>

<div id="maskLayer2" class="maskLayer" style="display: none;" >
    <h2>测试单</h2><textarea style="top: 20px;position: sticky;margin-right: 10px;" v-model="rootUrl" placeholder="请输入地址前缀，例如http://localhost">
    </textarea><textarea style="top: 20px;position: sticky;margin-right: 10px;" v-model="header" placeholder='请输入Json格式的公用请求头信息，例如{"Cookie":"123","token":"abc"}'>
    </textarea><el-button @click="download" style="background-color: #f3f3f3">下载文档</el-button>

 <template >
  <el-table
    :data="clazzs"
    style="width: 100%">
     <el-table-column
      label="控制器名称"
      prop="name">
    </el-table-column>
    <el-table-column
      label="包名"
      prop="packageName">
    </el-table-column>
    <el-table-column
      label="作者"
      prop="author" >
    </el-table-column>
    <el-table-column
      label="备注"
      prop="remark" show-overflow-tooltip = "true">
    </el-table-column>
    <el-table-column
      label="版本"
      prop="version">
    </el-table-column>
    <el-table-column
      label="接口数量"
      prop="method.length">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="getOne(scope.row)" type="text" name="查看" size="small">查看</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

 </div>


</div>
</body>
<script type="text/javascript">

var curWwwPath=window.document.location.href;
console.log(curWwwPath);
var pathName=window.document.location.pathname;
var pos=curWwwPath.indexOf(pathName);
console.log(pos);
var rootUrl=curWwwPath.substring(0,pos);
console.log(rootUrl);


new Vue({
            el: '#app',
            data: {
                text:"",
                model:"",
                header:'{"Cookie":"123","token":"abc"}',
                rootUrl:"http://localhost/",
                clazzs:[],
                type:"text",
                fullscreenLoading:false
            },
             mounted: function () {
                 //this.help();

             },
            methods: {
                handleClick(row) {
        console.log(row);
      },
                send:function(type,url,param){
                         $.ajax({
                        data : param,
                        type : type,
                        dataType: 'json',
                        url :url,
                        success : function(data) {
                            alert("发送成功");
                        }
                    })
                },
commit:function(type){
  this.type=type;
  if(type=="path"){
    this.text="C:/Users/0380009081/git/all";
  }else if(type=="git"){
 this.text="git.baseUrl =http://172.29.1.2/unicorn/platform/all.git\r\n" + 
      "git.dir =/Users/0380009081/git/interfacetest/all\r\n" + 
      "git.user =zhangkun@hxct.com\r\n" + 
      "git.pass =nobugnocode\r\n" + 
      "git.branch =dev\r\n" + 
      "#git.revision =1.0";
  }else{
this.text="package com.lz.zk;\r\n" + 
      "\r\n" + 
      "import java.io.IOException;\r\n" + 
      "import java.io.StringReader;\r\n" + 
      "import java.util.ArrayList;\r\n" + 
      "import java.util.Arrays;\r\n" + 
      "import java.util.HashMap;\r\n" + 
      "import java.util.List;\r\n" + 
      "import java.util.Map;\r\n" + 
      "import java.util.Map.Entry;\r\n" + 
      "import java.util.Properties;\r\n" + 
      "\r\n" + 
      "import org.springframework.beans.factory.annotation.Autowired;\r\n" + 
      "import org.springframework.beans.factory.annotation.Value;\r\n" + 
      "import org.springframework.http.HttpEntity;\r\n" + 
      "import org.springframework.http.HttpHeaders;\r\n" + 
      "import org.springframework.http.HttpMethod;\r\n" + 
      "import org.springframework.http.MediaType;\r\n" + 
      "import org.springframework.http.ResponseEntity;\r\n" + 
      "import org.springframework.util.LinkedMultiValueMap;\r\n" + 
      "import org.springframework.util.MultiValueMap;\r\n" + 
      "import org.springframework.web.bind.annotation.GetMapping;\r\n" + 
      "import org.springframework.web.bind.annotation.PathVariable;\r\n" + 
      "import org.springframework.web.bind.annotation.PostMapping;\r\n" + 
      "import org.springframework.web.bind.annotation.RequestMapping;\r\n" + 
      "import org.springframework.web.bind.annotation.RequestParam;\r\n" + 
      "import org.springframework.web.bind.annotation.RestController;\r\n" + 
      "import org.springframework.web.client.RestTemplate;\r\n" + 
      "\r\n" + 
      "import com.alibaba.fastjson.JSON;\r\n" + 
      "import com.lz.zk.git.GitUtil;\r\n" + 
      "import com.lz.zk.model.MethodModel;\r\n" + 
      "import com.lz.zk.model.Model;\r\n" + 
      "import com.lz.zk.model.Param;\r\n" + 
      "import com.lz.zk.regex.CodeUtil;\r\n" + 
      "\r\n" + 
      "/**\r\n" + 
      " * <控制器>\r\n" + 
      " * \r\n" + 
      " * @author 0380009081\r\n" + 
      " * @version 1.0\r\n" + 
      " */\r\n" + 
      "@RestController\r\n" + 
      "@RequestMapping(\"interface\")\r\n" + 
      "public class Controller {\r\n" + 
      "\r\n" + 
      " @Autowired\r\n" + 
      " RestTemplate httpService;\r\n" + 
      "\r\n" + 
      " @Autowired\r\n" + 
      " GitUtil gitService;\r\n" + 
      "\r\n" + 
      " @Value(\"${git.dir}\")\r\n" + 
      " private String dir;\r\n" + 
      "\r\n" + 
      " /**\r\n" + 
      "  * <自动从git上拉代码到本地>\r\n" + 
      "  * \r\n" + 
      "  * @param TbaseUrl  git地址\r\n" + 
      "  * @param Tdir      本地地址\r\n" + 
      "  * @param Tuser     用户名\r\n" + 
      "  * @param Tpass     密码\r\n" + 
      "  * @param Tbranch   分支\r\n" + 
      "  * @param Trevision 版本\r\n" + 
      "  * @return @\r\n" + 
      "  */\r\n" + 
      " @GetMapping(\"code/pull\")\r\n" + 
      " int codePull(String TbaseUrl, String Tdir, String Tuser, String Tpass, String Tbranch, String Trevision) {\r\n" + 
      "   return gitService.getGitConfigPull();\r\n" + 
      " }\r\n" + 
      "\r\n" + 
      " /**\r\n" + 
      "  * <提交>\r\n" + 
      "  * \r\n" + 
      "  * @param filed 文件類容\r\n" + 
      "  * @param type  类型 path,git,text\r\n" + 
      "  * @return\r\n" + 
      "  */\r\n" + 
      " @PostMapping(\"commit\")\r\n" + 
      " List<Model> commit(@RequestParam String filed, @RequestParam String type) {\r\n" + 
      "   if (\"path\".equals(type)) {\r\n" + 
      "     return CodeUtil.commitByUrl(filed);\r\n" + 
      "   } else if (\"git\".equals(type)) {\r\n" + 
      "     Properties proper = new Properties();\r\n" + 
      "     try {\r\n" + 
      "       proper.load(new StringReader(filed));\r\n" + 
      "       gitService.getGitPull(proper.getProperty(\"git.baseUrl\"), proper.getProperty(\"git.dir\"),\r\n" + 
      "           proper.getProperty(\"git.user\"), proper.getProperty(\"git.pass\"),\r\n" + 
      "           proper.getProperty(\"git.branch\"), proper.getProperty(\"git.revision\"));\r\n" + 
      "       return CodeUtil.commitByUrl(proper.getProperty(\"git.dir\"));\r\n" + 
      "     } catch (IOException e) {\r\n" + 
      "       e.printStackTrace();\r\n" + 
      "     }\r\n" + 
      "     return new ArrayList<Model>();\r\n" + 
      "   } else {\r\n" + 
      "     return Arrays.asList(CodeUtil.commit(filed));\r\n" + 
      "   }\r\n" + 
      " }\r\n" + 
      "\r\n" + 
      " /**\r\n" + 
      "  * <示例接口>\r\n" + 
      "  * @param id 文档id\r\n" + 
      "  * @return\r\n" + 
      "  */\r\n" + 
      " @GetMapping(\"download/{id}\")\r\n" + 
      " public int download(@PathVariable Integer id) {\r\n" + 
      "   return id;\r\n" + 
      " }\r\n" + 
      " \r\n" + 
      " /**\r\n" + 
      "  * <示例接口>\r\n" + 
      "  * @param id 文档id\r\n" + 
      "  * @return\r\n" + 
      "  */\r\n" + 
      " @GetMapping(\"download1\")\r\n" + 
      " public int download1(@RequestParam(required = true,defaultValue = \"10\") Integer id) {\r\n" + 
      "   return id;\r\n" + 
      " }\r\n" + 
      " \r\n" + 
      " @PostMapping(\"download\")\r\n" + 
      " public String download(List<Model> model) {\r\n" + 
      "//   Map<String, String> header = new LinkedHashMap<String, String>();\r\n" + 
      "//   header.put( \"streeName\",\"所属街道\");\r\n" + 
      "//   header.put(\"communityName\",\"所属社区\");\r\n" + 
      "//   header.put(\"type\",\"场景类型\");\r\n" + 
      "//   header.put(\"estateName\",\"区域名称\");\r\n" + 
      "//   header.put(\"fullAddress\",\"详细地址\");\r\n" + 
      "//   header.put( \"majorType\",\"设备大类\");\r\n" + 
      "//   header.put(\"minorType\",\"设备小类\");\r\n" + 
      "//   header.put(\"deviceName\",\"设备名称\");\r\n" + 
      "//   header.put(\"ip\",\"设备IP\");\r\n" + 
      "//   header.put(\"remark\",\"备注\");\r\n" + 
      "//   header.put(\"lastUpdateTime\",\"最后操作时间\");\r\n" + 
      "//   Map<String, Function<Object, String>> functions = new HashMap<String, Function<Object,String>>();\r\n" + 
      "//   IEstateService estateService = (IEstateService) ServiceModuleFactory.getFramework().getModuleManager().getModule(ServiceModuleFactory.SYS_PSCM, IEstateService.APP_ID);\r\n" + 
      "//   List<DataDictionaryItem> dicts = estateService.getDataDictionary(\"LOCATION_TYPE\");\r\n" + 
      "//   Map<String, String> map = dicts.stream().collect(Collectors.toMap(DataDictionaryItem::getDataCode, DataDictionaryItem::getDataName));\r\n" + 
      "//   Function<Object,String> function1 = s->{return s==null?\"-\":String.valueOf(s);};\r\n" + 
      "//   Function<Object,String> function2 = s->{String name = map.get(s);return name==null?\"-\":name;};\r\n" + 
      "//   Function<Object,String> function3 = s->{return s==null?\"\":new SimpleDateFormat(\"yyyy-MM-dd HH:mm\").format(s);};\r\n" + 
      "//   functions.put(\"streeName\", function1);\r\n" + 
      "//   functions.put(\"communityName\", function1);\r\n" + 
      "//   functions.put(\"type\", function2);\r\n" + 
      "//   functions.put(\"estateName\", function1);\r\n" + 
      "//   functions.put(\"lastUpdateTime\", function3);\r\n" + 
      "//   try {\r\n" + 
      "//     new MyExcelExportOutHelper<PscmDeviceBaseInfoView>(header, devices, functions).export(\"告警设备.xlsx\", true, false, response);\r\n" + 
      "//   } catch (Exception e) {\r\n" + 
      "//     e.printStackTrace();\r\n" + 
      "//     throw new AppModuleErrorException(\"导出失败!\");\r\n" + 
      "//   }\r\n" + 
      "   return \"未开通\";\r\n" + 
      " }\r\n" + 
      "\r\n" + 
      " /**\r\n" + 
      "  * <接口自动测试>\r\n" + 
      "  * \r\n" + 
      "  * @param methods 方法\r\n" + 
      "  * @param header  请求头，cookie\r\n" + 
      "  * @param rootUrl ip和端口号\r\n" + 
      "  * @return\r\n" + 
      "  */\r\n" + 
      " @SuppressWarnings(\"unchecked\")\r\n" + 
      " @PostMapping(\"test\")\r\n" + 
      " public List<MethodModel> test(String methods, String header, String rootUrl) {\r\n" + 
      "//   String[] paramType1 = {\"byte\", \"short\", \"int\", \"long\", \"float\", \"double\", \"boolean\",\"char\"};\r\n" + 
      "//   String[] paramType2 = {\"Byte\", \"Short\", \"Integer\", \"Long\", \"Float\", \"Double\", \"Boolean\",\"Character\",\"Object\"};\r\n" + 
      "//   String[] paramType3 = {\"List\", \"Map\"};\r\n" + 
      "   Map<String, String> headerMap = JSON.parseObject(header, HashMap.class);\r\n" + 
      "   List<MethodModel> mets = JSON.parseArray(methods, MethodModel.class);\r\n" + 
      "   if (methods != null) {\r\n" + 
      "     for (MethodModel met : mets) {\r\n" + 
      "       long start = System.currentTimeMillis();\r\n" + 
      "       if (met.getMethodType() == null) {\r\n" + 
      "         met.setMethodRunstatus(\"错误\");\r\n" + 
      "         met.setMethodRunresult(\"未知的请求类型\");\r\n" + 
      "         continue;\r\n" + 
      "       }\r\n" + 
      "       HttpHeaders headers = new HttpHeaders();\r\n" + 
      "       if (header != null) {\r\n" + 
      "         for (Entry<String, String> entry : headerMap.entrySet()) {\r\n" + 
      "           headers.add(entry.getKey(), entry.getValue());\r\n" + 
      "         }\r\n" + 
      "       }\r\n" + 
      "       switch (met.getMethodType()) {\r\n" + 
      "       case \"POST\": {\r\n" + 
      "         headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);\r\n" + 
      "         headers.add(\"Accept\", MediaType.APPLICATION_JSON.toString());\r\n" + 
      "         if (met.getMethodHttpHeader() != null) {\r\n" + 
      "           for (Entry<String, String> entry : met.getMethodHttpHeader().entrySet()) {\r\n" + 
      "             headers.add(entry.getKey(), entry.getValue());\r\n" + 
      "           }\r\n" + 
      "         }\r\n" + 
      "         // 添加参数\r\n" + 
      "         MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();\r\n" + 
      "         for (Param par : met.getMethodParam()) {\r\n" + 
      "           if (met.getMethodUrl().indexOf(\"{\" + par.getParamName() + \"}\") != -1) {\r\n" + 
      "             met.setMethodRealUrl(met.getMethodUrl().replaceAll(\"{\" + par.getParamName() + \"}\",\r\n" + 
      "                 par.getParamValue() + \"\"));\r\n" + 
      "           } else {\r\n" + 
      "             if (par.getParamType() != null && par.getParamType().equals(\"Integer\")) {\r\n" + 
      "               map.put(par.getParamName(), par.getParamValue() == null ? null\r\n" + 
      "                   : Arrays.asList(Integer.parseInt(\"\" + par.getParamValue())));\r\n" + 
      "             } else if (par.getParamType() != null && par.getParamType().equals(\"String\")) {\r\n" + 
      "               map.put(par.getParamName(),\r\n" + 
      "                   par.getParamValue() == null ? null : Arrays.asList(\"\" + par.getParamValue()));\r\n" + 
      "             } else\r\n" + 
      "               map.put(par.getParamName(),\r\n" + 
      "                   par.getParamValue() == null ? null : Arrays.asList(par.getParamValue()));\r\n" + 
      "           }\r\n" + 
      "\r\n" + 
      "         }\r\n" + 
      "         // HttpEntity<MultiValueMap<String, String>> request = new\r\n" + 
      "         // HttpEntity<MultiValueMap<String, String>>(map, headers);\r\n" + 
      "         HttpEntity<Object> formEntity = new HttpEntity<Object>(map, headers);\r\n" + 
      "         try {\r\n" + 
      "           ResponseEntity<String> result = httpService.exchange(rootUrl + met.getMethodRealUrl(),\r\n" + 
      "               HttpMethod.POST, formEntity, String.class);\r\n" + 
      "           met.setMethodRunresult(result.getBody());\r\n" + 
      "           met.setMethodRunstatus(\"\" + result.getStatusCode());\r\n" + 
      "         } catch (Exception e) {\r\n" + 
      "           e.printStackTrace();\r\n" + 
      "           // 捕捉HTTP异常\r\n" + 
      "           met.setMethodRunresult(e.getMessage());\r\n" + 
      "           met.setMethodRunstatus(\"\" + 500);\r\n" + 
      "         }\r\n" + 
      "         break;\r\n" + 
      "       }\r\n" + 
      "       case \"GET\": {\r\n" + 
      "         MediaType type = MediaType.parseMediaType(\"application/json; charset=UTF-8\");\r\n" + 
      "         headers.setContentType(type);\r\n" + 
      "         headers.add(\"Accept\", MediaType.APPLICATION_JSON.toString());\r\n" + 
      "         if (met.getMethodHttpHeader() != null) {\r\n" + 
      "           for (Entry<String, String> entry : met.getMethodHttpHeader().entrySet()) {\r\n" + 
      "             headers.add(entry.getKey(), entry.getValue());\r\n" + 
      "           }\r\n" + 
      "         }\r\n" + 
      "         String param = \"\";\r\n" + 
      "         if (met.getMethodParam().size() > 0) {\r\n" + 
      "           param = \"?\";\r\n" + 
      "           for (Param par : met.getMethodParam()) {\r\n" + 
      "             if (met.getMethodUrl().indexOf(\"{\" + par.getParamName() + \"}\") != -1) {\r\n" + 
      "               met.setMethodRealUrl(met.getMethodUrl().replaceAll(\"\\\\{\" + par.getParamName() + \"\\\\}\",\r\n" + 
      "                   par.getParamValue() + \"\"));\r\n" + 
      "             } else {\r\n" + 
      "               param += par.getParamName() + \"=\"\r\n" + 
      "                   + (par.getParamValue() == null ? \"\" : par.getParamValue()) + \"&\";\r\n" + 
      "             }\r\n" + 
      "           }\r\n" + 
      "           param = param.substring(0, param.length() - 1);\r\n" + 
      "         }\r\n" + 
      "         HttpEntity<String> formEntity = new HttpEntity<String>(null, headers);\r\n" + 
      "         try {\r\n" + 
      "           ResponseEntity<String> result = httpService.exchange(rootUrl + met.getMethodRealUrl() + param,\r\n" + 
      "               HttpMethod.GET, formEntity, String.class);\r\n" + 
      "           met.setMethodRunresult(result.getBody());\r\n" + 
      "           met.setMethodRunstatus(\"\" + result.getStatusCode());\r\n" + 
      "         } catch (Exception e) {\r\n" + 
      "           e.printStackTrace();\r\n" + 
      "           // 捕捉HTTP异常\r\n" + 
      "           met.setMethodRunresult(e.getMessage());\r\n" + 
      "           met.setMethodRunstatus(\"\" + 500);\r\n" + 
      "         }\r\n" + 
      "         break;\r\n" + 
      "       }\r\n" + 
      "       case \"PUT\": {\r\n" + 
      "         break;\r\n" + 
      "       }\r\n" + 
      "       case \"DELETE\": {\r\n" + 
      "         break;\r\n" + 
      "       }\r\n" + 
      "       default: {\r\n" + 
      "         met.setMethodRunstatus(\"错误\");\r\n" + 
      "         met.setMethodRunresult(\"未知的请求类型\");\r\n" + 
      "         break;\r\n" + 
      "       }\r\n" + 
      "       }\r\n" + 
      "       long end = System.currentTimeMillis();\r\n" + 
      "       met.setMethodRuntime(end - start + \"毫秒\");\r\n" + 
      "     }\r\n" + 
      "   }\r\n" + 
      "   return mets;\r\n" + 
      " }\r\n" + 
      "}\r\n" + 
      "";
  }
},
history:function(){
this.showDiv();
if(parent.vue){  //判断是否存在父窗口
    console.log("存在父窗口");
   this.clazzs = parent.vue.model
  
}else{
    console.log("不存在父窗口");
  
}
},
commitText:function (){
    var self=this;
    console.log(self.text);
    $.ajax({
                        data : {
                            filed:self.text,
                            type:self.type
                        },
                        type : 'POST',
                        dataType: 'json',
                        url :rootUrl+'/interface/commit',
                        xhrFields: {
                            withCredentials: true
                        },
                        beforeSend: function(){
     self.fullscreenLoading=true
    },
                        success : function(data) {
                          if(data.length>0){
                            self.showDiv(2);
                            self.clazzs=data;
                          }
                         
                         if(parent.vue){  //判断是否存在父窗口
    console.log("存在父窗口");
    parent.vue.model=self.clazzs
  
}else{
    console.log("不存在父窗口");
  
}
                        },
                            complete: function(){
     self.fullscreenLoading=false
    },error:function(XMLHttpRequest){
        if(XMLHttpRequest.status!=200)alert(XMLHttpRequest.responseText);
    }
                    })

//     var xhr = new XMLHttpRequest();
// //  xhr.timeout = 3000;
// //  xhr.ontimeout = function (event) {
// //      alert("请求超时！");
// //    }
//     var formData = new FormData();
//     alert(document.getElementById('textArea').value);
//     formData.append('filed', document.getElementById('textArea').value);
//     xhr.open('POST', 'http://localhost:8001/interface/commit');
//     xhr.send(formData);
//     xhr.onreadystatechange = function () {
//         if (xhr.readyState == 4 && xhr.status == 200) {
//             showDiv();
//         }
//         else {
//             alert(xhr.statusText);
//         }
//     }
},
 getOne:function(e){
  var self =this;
self.model =e;
self.showDiv(1);
 },

showDiv:function (index) { 
    document.getElementById('popWindow').style.display = 'block'; 
    if(index==1){
      document.getElementById('maskLayer2').style.display = 'none'; 
    document.getElementById('maskLayer1').style.display = 'block'; 
    }else{
      document.getElementById('maskLayer1').style.display = 'none'; 
    document.getElementById('maskLayer2').style.display = 'block'; 
    }

} ,

closeDiv:function () { 
    document.getElementById('popWindow').style.display = 'none'; 

    document.getElementById('maskLayer1').style.display = 'none'; 

    document.getElementById('maskLayer2').style.display = 'none'; 
    } ,

show:function (){
    this.text="示例";
},

help:function (){
    this.text="本接口自动生成利用正则表达式，目前支持提交控制器文本，服务器仓库路径,远程仓库3种，只要符合示例规范的resultful控制器均可使用该方式生成文档.\r\n" + 
      "使用方式：\r\n" + 
      "         1.文本类型：点击文本按钮，将controller粘贴到此文本域，再点击提交即可；\r\n" + 
      "         2.服务器代码路径：点击路径，将代码文件夹所在服务器目录粘贴到此文本域，再点击提交即可；\r\n" + 
      "         3.远程git仓库：点击仓库，在此文本域修改自己git的配置，再点击提交即可。";
},


test:function(type,e){
        var self=this;
        if(type==0){
          var arr = [];
          arr[0]=e;
          self.send(JSON.stringify(arr),0);
        }else if(type==1){console.log(self.model.method);
         self.send(JSON.stringify(self.model.method),1);
        }
},
send:function(e,type){
  var self=this;
   $.ajax({
                        data : {
                            header:self.header,
                            methods:e,
                            rootUrl:self.rootUrl
                        },
                        type : 'POST',
                        dataType: 'json',
                        url :rootUrl+'/interface/test',
                        xhrFields: {
                            withCredentials: true
                        },
                        beforeSend: function(){
     self.fullscreenLoading=true
    },
                        success : function(data) {
                            if(type==0){
                                for(var t=0;t<self.model.method.length;t++){
                                    if(self.model.method[t].methodUrl==data[0].methodUrl){
                                       Vue.set(self.model.method,t,data[0]);
                                        //self.model.method[t]=data[0];
                                    }
                                }
                              }else if(type==1){
                                self.model.method = data;
                              }
                             if(parent.vue){  //判断是否存在父窗口
    console.log("存在父窗口");
    parent.vue.model=self.clazzs
  
}else{
    console.log("不存在父窗口");
  
}
                        },
                            complete: function(){
     self.fullscreenLoading=false
    },error:function(XMLHttpRequest){
        if(XMLHttpRequest.status!=200)alert(XMLHttpRequest.responseText);
    }
                    })
},


                download : function (e) {

                    console.log(this.clazzs);
var self=this;
//下载
self.fullscreenLoading = true;
                        setTimeout(function () {
                            var form = $("<form>");
                            form.attr("style", "display:none");
                            form.attr("id", "downloadForm");
                            form.attr("target", "");
                            form.attr("method", "post");
                            form.attr("action", rootUrl+'/interface/download');
                            var input1 = $("<input>");
                            input1.attr("type", "hidden");
                            input1.attr("name", "model");
                            if(e==1){
                              input1.attr("value", "["+JSON.stringify(self.model)+"]");
                            }else{
                              input1.attr("value", JSON.stringify(self.clazzs));
                            }
                            
                            
                            $("body").append(form);
                            form.append(input1);
                            form.submit();
                            var downloadForm = $('#downloadForm')[0];
                            downloadForm.parentNode.removeChild(downloadForm);
                            self.fullscreenLoading = false;
                          if(parent.vue){  //判断是否存在父窗口
    console.log("存在父窗口");
    parent.vue.model=self.clazzs
  
}else{
    console.log("不存在父窗口");
  
}
                        },10000);

    //                  $.ajax({
    //                     type : 'post',
    //                     dataType: 'json',
    //                     data:{model:JSON.stringify(self.clazzs)},
    //                     url :'http://localhost:8001/interface/download',
    //                     beforeSend: function(){
    //  self.fullscreenLoading=true
    // },
    //                     success : function(data) {
    //                         console.log(data);
    //                     },
    //                          complete: function(){
    //  self.fullscreenLoading=false
    // },error:function(XMLHttpRequest){
    //     if(XMLHttpRequest.status!=200)alert(XMLHttpRequest.responseText);
    // }
    //                 })

                },
                   

            },
            computed:{
               
            },
        });

</script>

<style>
h2{
    display: inline-block;
    width: 50%
}
.popWindow { 
background-color:#9D9D9D; 
width: 100%; 
height: 100%; 
left: 0; 
top: 0; 
filter: alpha(opacity=50); 
opacity: 0.5; 
z-index: 1; 
position: absolute; 

} 
.maskLayer { 
background-color:#f3f3f3; 
width: 80%; 
height: 80%; 
line-height: 30px; 
margin: auto 10%;
color:#333; 
z-index: 2; 
position: absolute; 
text-align:center; 
left: 0px;
top:10%;
overflow: scroll;
    overflow-x: auto;
    overflow-y: auto;
}
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }

</style>
</html>